﻿@model QuanLySanXuat.Models.OrderSummaryFormModels
@{
    ViewBag.Title = "Kết thúc sản xuất";
}
<link href="@Url.Content("~/ContentTMT/dateui.css")" rel="stylesheet" />
<script type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#EndDate").datepicker();
            $("#StartDate").datepicker();
            $("#EndDate").datepicker("option", "dateFormat", "dd/mm/yy");
            $("#StartDate").datepicker("option", "dateFormat", "dd/mm/yy");
        });
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#CheckValid').bootstrapValidator({
            message: 'This value is not valid',
            excluded: [':disabled'],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                Code: {
                    validators: {
                        notEmpty: {
                            message: 'Mã không để trống'
                        }
                    }
                },
                OrderID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn mã sản phẩm'
                        }
                    }
                },
                TotalCost: {
                    validators: {
                        integer: {
                            message: 'Chi phí phải là số'
                        }
                    }
                },
                Quantity: {
                    validators: {
                        integer: {
                            message: 'Số lượng phải là số'
                        }
                    }
                },
                UnitPrice: {
                    validators: {
                        integer: {
                            message: 'Phải là số'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');
            $("#EndDate").datepicker("option", "dateFormat", "mm/dd/yy");
            $("#StartDate").datepicker("option", "dateFormat", "mm/dd/yy");
            // Use Ajax to submit form data
            $.ajax({
                type: "POST",
                url: '@Url.Action("Save", "OrderSummary")',
                async: false,
                cache: false,
                data: $('#CheckValid').serialize(),
                success: function (result) {
                    location.href = '@Url.Action("Index", "OrderSummary")'
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        });
    });
</script>
<div id="breadcrumb">
    <div class="container">
        <div id="con_top">
            <div class="c_container">
                <h3>Kết thúc sản xuất</h3>
            </div>
        </div>
    </div>
</div>
<form class="form-horizontal" role="form" id="CheckValid" style="margin-top: 10px;">
    @if (Model == null)
    {
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Số ký hiệu (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" />
                    <input type="text" class="form-control" id="Code" name="Code" placeholder="Code">
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Lệnh thực hiện sản xuất(*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="HOrderID" name="HOrderID" />
                    <input type="hidden" id="HOrderProcessID" name="HOrderProcessID" />
                    @Html.DropDownList("OrderProcessID", new SelectList(ViewData["OrderProcess"] as IEnumerable<Data.Models.OrderProcess>, "ID", "Code"), "Chọn lệnh thực hiện sản xuất", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày bắt đầu</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                         <input type="hidden" id="ProductModelID" name="ProductModelID" />
                        <input type="text" class="form-control" id="StartDate" name="StartDate">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày kết thúc</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="EndDate" name="EndDate">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Số lượng</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="Quantity" name="Quantity">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Tổng chi phí</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="TotalCost" name="TotalCost">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Giá thành sản phẩm</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="UnitPrice" name="UnitPrice">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Mô tả sản phẩm</label>
                <div class="col-sm-7">
                    <textarea id="Description" name="Description" class="form-control" rows="4" placeholder="Mô tả"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Kết quả đánh giá chất lượng</label>
                <div class="col-sm-7">
                    <textarea id="Evaluation1" name="Evaluation1" class="form-control" rows="4" placeholder="Kết quả đánh giá chất lượng"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Kết quả đánh giá công việc</label>
                <div class="col-sm-7">
                    <textarea id="Evaluation2" name="Evaluation2" class="form-control" rows="4" placeholder="Kết quả đánh giá công việc"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Ghi chú</label>
                <div class="col-sm-7">
                    <textarea id="Note" name="Note" class="form-control" rows="4" placeholder="Ghi chú"></textarea>
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Số ký hiệu (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" value="@Model.ID"/>
                    <input type="text" class="form-control" id="Code" name="Code" placeholder="Code" value="@Model.Code" >
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Lệnh kết thúc sản xuất(*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="HOrderID" name="HOrderID" value="@Model.OrderID"/>
                     <input type="hidden" id="HOrderProcessID" name="HOrderProcessID" value="@Model.OrderProcessID"/>
                    @Html.DropDownList("OrderProcessID", new SelectList(ViewData["OrderProcess"] as IEnumerable<Data.Models.OrderProcess>, "ID", "Code", @Model.OrderProcessID), "Chọn lệnh thực hiện sản xuất", new { @class = "form-control",@disabled="true" })
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày bắt đầu</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                         <input type="hidden" id="ProductModelID" name="ProductModelID" value="@Model.ProductModelID"/>
                        <input type="text" class="form-control" id="StartDate" name="StartDate" value="@Convert.ToDateTime(@Model.StartDate).ToShortDateString()">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày kết thúc</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="EndDate" name="EndDate" value="@Convert.ToDateTime(@Model.EndDate).ToShortDateString()">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Số lượng</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Quantity" name="Quantity" value="@Model.Quantity">
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Tổng chi phí</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="TotalCost" name="TotalCost" value="@Model.TotalCost">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Giá thành sản phẩm</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="UnitPrice" name="UnitPrice" value="@Model.UnitPrice">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Mô tả sản phẩm</label>
                <div class="col-sm-7">
                    <textarea id="Description" name="Description" class="form-control" rows="4" placeholder="Mô tả">@Model.Description</textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Kết quả đánh giá chất lượng</label>
                <div class="col-sm-7">
                    <textarea id="Evaluation1" name="Evaluation1" class="form-control" rows="4" placeholder="Kết quả đánh giá chất lượng">@Model.Evaluation1</textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Kết quả đánh giá công việc</label>
                <div class="col-sm-7">
                    <textarea id="Evaluation2" name="Evaluation2" class="form-control" rows="4" placeholder="Kết quả đánh giá công việc">@Model.Evaluation2</textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-4 control-label">Ghi chú</label>
                <div class="col-sm-7">
                    <textarea id="Note" name="Note" class="form-control" rows="4" placeholder="Mô tả">@Model.Note</textarea>
                </div>
            </div>
        </div>
    }
    <div class="form-group">
        <div class="c_container col-sm-10 col-sm-offset-1" id="processDetail">
            <div class="cleardiv"></div>
            <div class="btn-group">
                <div class="btn-group">
                    <button id="btnSaveSale" type="submit" class="btn btn-defaultxero">Lưu</button>
                </div>
            </div>
            <div class="btn-group">
                <button id="btnCancelSale" type="button" onclick="javascript: location.href = '/OrderSummary';" class="btn btn-defaultxero">Hủy</button>
            </div>
        </div>
    </div>

</form>


<script type="text/javascript">
    $(document).ready(function () {
        $("#OrderProcessID").change(function () {
            if (this.value != "") {
                GetDetail(this.value);
            }
        });
    });
    function GetDetail(element) {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetDetail", "OrderSummary")',
            async: false,
            cache: false,
            data: { ID: element },
            success: function (result) {
                $('#Quantity').val(result.Quantity);
                $('#TotalCost').val(result.TotalCost);
                $('#UnitPrice').val(result.UnitPrice);
                $('#HOrderID').val(result.OrderID);
                $('#HOrderProcessID').val(element);
                $('#ProductModelID').val(result.ProductModelID);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(xhr.responseText);
                alert(thrownError);
            }
        });
    }
</script>
